﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;
using Microsoft.AspNetCore.Http;
using Microsoft.AspNetCore.Mvc;
using Microsoft.Extensions.Logging;
using WebAppHappyNewYear.Models;

namespace WebAppHappyNewYear.Controllers
{
    public class FirstMvcController : Controller
    {
        private readonly ILogger<FirstMvcController> _logger;
        public FirstMvcController(ILogger<FirstMvcController> logger)
        {
            _logger=logger;
        }

        public IActionResult Index()
        {
            _logger.LogInformation("Information");
            _logger.LogTrace("Trace");

            #region ViewData

            base.ViewData["User1"] = new CurrentUser()
            {
                Id = 7,
                Name = "Y",
                Account = "Nerol",
                Email = "123@321.com",
                Password = "逻辑",
                LoginTime = DateTime.Now
            };

            base.ViewData["Something"] = 12345;

            #endregion

            #region ViewBag
            base.ViewBag.Name = "Whj";
            base.ViewBag.Description = "Teacher";
            base.ViewBag.User = new CurrentUser()
            {
                Id = 7,
                Name = "YYY",
                Account = "Nerol",
                Email = "123@321.com",
                Password = "逻辑",
                LoginTime = DateTime.Now
            };


            #endregion


            #region TempData

            base.TempData["User"] = new CurrentUser()
            {
                Id = 79,
                Name = "ASF",
                Account = "KALOSS",
                Email = "JOP@321.com",
                Password = "格瑞特",
                LoginTime = DateTime.Now
            };



            #endregion


            #region Session:服务器内存的一段内容

            if (string.IsNullOrWhiteSpace(this.HttpContext.Session.GetString("CurrentUserSession")))
            {
                base.HttpContext.Session.SetString("CurrentUserSession", Newtonsoft.Json.JsonConvert.SerializeObject(
                    new CurrentUser()
                    {
                        Id = 99,
                        Name = "颇有天赋的",
                        Account = "咯额我热",
                        Email = "xxccv@321.com",
                        Password = "含运费",
                        LoginTime = DateTime.Now
                    }
                    ));
            }

            #endregion


            #region Model

            return View(new CurrentUser()
            {
                Id = 9,
                Name = "六点半",
                Account = "我的狗",
                Email = "kobe@321.com",
                Password = "dfeg",
                LoginTime = DateTime.Now
            });


            #endregion
        }
    }
}